# coding:UTF-8
# ________________________
# Project_Name:pyzidonghua
# File_Name:Administrator
# Author:Administrator
# Date_Time:2022/5/16 10:51
# Description:
# ________________________

import unittest  # 导入测试框架
from appium import webdriver #导入
import time
from selenium.webdriver.common.by import By
from appium.webdriver.common.touch_action import TouchAction


class CalculatorTest(unittest.TestCase):

    def setUp(self) -> None:
        # 手机设置
        desired_caps = {}
        desired_caps['platformName'] = 'Android'  # 系统名称
        desired_caps['platformVersion'] = '7.1.2'  # 系统的版本号
        desired_caps['deviceName'] = 'Android Emulator'  # 设备名称，这里是虚拟机，这个没有严格的规定
        desired_caps['appPackage'] = 'com.netease.cloudmusic'  # APP包名
        desired_caps['appActivity'] = 'com.netease.cloudmusic.activity.LoadingActivity'  # APP入口的activity
        desired_caps['noReset'] = True  # 不重置app的缓存文件
        desired_caps['unicodeKeyboard'] = True  # 设置键盘支持中文输入
        desired_caps['resetKeyboard'] = True  # 重置键盘

        # 连接appium server，告诉appium，代码要操作哪个设备上的哪个APP
        # 启动手机上App
        self.driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)


    def test(self):
        time.sleep(15)
        #基于元素操作
        ele = self.driver.find_element(By.XPATH,"//android.widget.TextView[@text='排行榜']")
        TouchAction(self.driver).tap(ele).perform()
        # 基于坐标操作
        # TouchAction(self.driver).tap(None,345,333).perform()  #点击排行榜

        time.sleep(15)



    def tearDown(self) -> None:
        self.driver.quit()
